﻿using System.Collections.Generic;
using System.Linq;
using AutoMapper;

namespace BestEasyCMS.Service.Mappers
{
    public class Convert<TView, TEntity>
    {
        public static TView ToView(TEntity entity)
        {
            return Mapper.Map<TEntity, TView>(entity);
        }

        public static TEntity ToEntity(TView view)
        {
            return Mapper.Map<TView, TEntity>(view);
        }

        public static IEnumerable<TView> ToViews(IEnumerable<TEntity> entitys)
        {
            return entitys.Select(ToView).ToList();
        }

        public static IEnumerable<TEntity> ToEntitys(IEnumerable<TView> views)
        {
            return views.Select(ToEntity).ToList();
        }

        public static IList<TView> ToViews(IList<TEntity> entitys)
        {
            return entitys.Select(ToView).ToList();
        }

        public static IList<TEntity> ToEntitys(IList<TView> views)
        {
            return views.Select(ToEntity).ToList();
        }
    }
}
